package com.zengge.zbc.controller;

import com.zengge.zbc.dto.Result;
import com.zengge.zbc.dto.Room;
import com.zengge.zbc.service.RoomService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;

@RestController
@RequestMapping("/room")
public class RoomController {

    private final RoomService roomService;
    @Autowired
    public RoomController(RoomService roomService) {
        this.roomService = roomService;
    }

    @PostMapping("/saveOrUpdateRoomInfo")
    public Result<String> saveOrUpdateRoomInfo(@RequestBody Room room,
                                               @RequestAttribute("userId") long userId) {
        return Result.create(roomService.saveOrUpdateRoomInfo(room,userId));
    }

    @GetMapping("/roomListGet")
    public Result<List<Room>> roomListGet(@RequestAttribute("userId") long userId) {
        return Result.create(roomService.roomListGet(userId));
    }

    @GetMapping("/roomGet")
    public Result<Room> roomGet(@RequestAttribute("userId") long userId,
                                @RequestParam("roomId") String roomId) {
        return Result.create(roomService.roomGet(roomId,userId));
    }

    @GetMapping("/roomDelete")
    public Result<Boolean> roomDelete(@RequestParam("roomId") String roomId){
        roomService.deleteRoomId(roomId);
        return Result.create(true);
    }


}
